<?php
$this->Html->scriptBlock($scriptWindowMsg, array('inline' => false));
$this->Html->scriptBlock($scriptDate, array('inline' => false));
$this->Html->scriptBlock($reportScript, array('inline' => false));
$this->Html->script(array('accountresumes'), false);
$formUrl = array('controller' => 'accountresumes', 'action' => 'edit');
echo $this->Form->create('Accountresume', array('url' => $formUrl, 'type' => 'text'));
echo $this->Form->input('id');
?>
<div class="title-body-content"><?php echo $title_for_layout; ?><a class="checkfrm" rel="edit"></a></div>
<div class="wrapper-form-account-resume clearfix">
    <div class="wrapper-date clearfix">
        <span class="size-span"><?php echo __('Date'); ?> :</span>
        <?php
        echo $this->Form->text('date', array(
            'value' => $this->Layout->formatDate($this->data['Accountresume']['date']),
            'class' => 'sel-date',
            'readonly' => 'readonly',
            'label' => false,
            'div' => false,)
        );
        ?> <!--<label class="error-message">(*)</label>-->
    </div>
    <div class="wrapper-reference-page4 clearfix">
        <span class="size-span"><?php echo __('Reference #'); ?> :</span>
        <?php
        echo $this->Form->input('refid_edit', array(
            'class' => 'inp-reference-page4 size-inp-reference',
            'label' => false,
            'div' => false,)
        );
        echo $this->Form->input('refid', array(
            'type' => 'hidden',)
        );
        ?>
    </div>
    <div class="wrapper-producing-page4 clearfix">
        <table cellspacing="0" cellpadding="0" border="0">
            <tr>
                <td style="text-align:left; width:138px; vertical-align:top">
                    <span class="size-span"><?php echo __('Producer'); ?> :</span>
                </td>
                <td>
                    <?php
                    echo $this->Form->input('Producingbroker.Producingbroker', array(
                        'multiple' => false,
                        'empty' => false,
                        'class' => 'size-sel1-page4',
                        'label' => false,
                        'div' => false,)
                    );
                    foreach ($cur_data_producing_brokers as $key => $value) {
                        echo '<div class="contactField" style="text-align:left">';
                        echo '   <span class="size-span" style="width: 260px; float:left">';
                        echo         $value;
                        echo '       <input type="hidden" name="Producingbrokers[]" value="' . $key . '" />';
                        echo '   </span>';
                        echo '   <span style="float:right; font-weight:bold"><a class="removeContactField" href="JavaScript:void(0);" title="' . $value . '" rel="2:::' . $key . '">X</a></span>';
                        echo '</div>';
                    }
                    ?>
                    <span id="Producingbroker"></span>
                </td>
                <td style="vertical-align:top">
                    <ul class="button-form-input">
                        <li><a href="JavaScript:void(0);" class="addContactField" rel="2">Add</a><!--<div class="space3">|</div>--></li>
                        <!--<li><a href="JavaScript:void(0);" class="openWin" rel="2">New</a></li>-->
                    </ul>
                </td>
            </tr>
        </table>
    </div>
    <div class="wrapper-rein-page4 clearfix">
        <table cellspacing="0" cellpadding="0" border="0">
            <tr>
                <td style="text-align:left; width:138px; vertical-align:top">
                    <span class="size-span"><?php echo __('Reinsured'); ?> :</span>
                </td>
                <td>
                    <?php
                    echo $this->Form->input('reinsured', array(
                        'class' => 'inp-reference-page4 size-inp-reference',
                        'label' => false,
                        'div' => false,)
                    );
                    ?>  <!--<label class="error-message">(*)</label>-->
                </td>
            </tr>
        </table>
    </div>
    <div class="wrapper-ori-insurer-page4 clearfix">
        <table cellspacing="0" cellpadding="0" border="0">
            <tr>
                <td style="text-align:left; width:138px; vertical-align:top">
                    <span class="size-span"><?php echo __('Original Insured'); ?> :</span>
                </td>
                <td>
                    <?php
                    echo $this->Form->input('original_insured', array(
                        'class' => 'inp-reference-page4 size-inp-reference',
                        'label' => false,
                        'div' => false,)
                    );
                    ?> <!--<label class="error-message">(*)</label>-->
                </td>
            </tr>
        </table>
    </div>
    <div class="wrapper-ori-insurer-page4 clearfix">
        <table cellspacing="0" cellpadding="0" border="0">
            <tr>
                <td style="text-align:left; width:138px; vertical-align:top">
                    <span class="size-span"><?php echo __('Markets'); ?> :</span>
                </td>
                <td>
                    <?php
                    echo $this->Form->input('Market.Market', array(
                        'multiple' => false,
                        'empty' => false,
                        'class' => 'size-sel1-page4',
                        'label' => false,
                        'div' => false,)
                    );
                    foreach ($cur_data_markets as $key => $value) {
                        echo '<div id="marketField' . $key . '" class="marketField" style="text-align:left">';
                        echo '   <span class="size-span" style="width: 260px; float:left">';
                        echo         $value;
                        echo '       <input type="hidden" name="Markets[]" value="' . $key . '" />';
                        echo '   </span>';
                        echo '   <span style="float:right; font-weight:bold"><a class="removeMarketField" href="JavaScript:void(0);" title="' . $value . '" rel="4:::' . $key . '">X</a></span>';
                        echo '</div>';
                    }
                    ?>
                    <span id="Market"></span>
                </td>
                <td style="vertical-align:top">
                    <ul class="button-form-input">
                        <li><a href="JavaScript:void(0);" class="addMarketField" rel="4">Add</a><!--<div class="space3">|</div>--></li>
                        <!--<li><a href="JavaScript:void(0);" class="openWinMarket" rel="4">New</a></li>-->
                    </ul>
                </td>
            </tr>
        </table>
    </div>
    <div class="wrapper-insurance-type-page4 clearfix">
        <span class="size-span"><?php echo __('Insurance Type'); ?> :</span>
        <?php
        echo $this->Form->input('Insurancetype.Insurancetype', array(
            'multiple' => false,
            'selected' => $this->request->data['Accountresume']['insurancetype_id'],
            'empty' => false,
            'class' => 'size-sel1-page4',
            'label' => false,
            'div' => false,)
        );
        ?>
    </div>
    <div class="wrapper-insurance-type-page4 clearfix">
        <span class="size-span"><?php echo __('Insurance Type Detail'); ?> :</span>
        <?php
        echo $this->Form->textarea('insurancetype_detail', array(
            'class' => 'aih-expense-textarea-from',
            'style' => 'width:41%; margin-left:0',
            'label' => false,
            'div' => false,)
        );
        ?>
    </div>
    <div class="wrapper-insurance-period-page4 clearfix">
        <span class="size-span"><?php echo __('Insurance Period'); ?> :</span>
        <?php
        echo $this->Form->text('from_date', array(
            'value' => $this->Layout->formatDate($this->data['Accountresume']['from_date']),
            'class' => 'sel-date',
            'readonly' => 'readonly',
            'label' => false,
            'div' => false,)
        );
        ?> <!--<label class="error-message">(*)</label>-->
        <span class="sp-to"><?php echo __('To'); ?></span>
        <?php
        echo $this->Form->text('to_date', array(
            'value' => $this->Layout->formatDate($this->data['Accountresume']['to_date']),
            'class' => 'sel-date',
            'readonly' => 'readonly',
            'label' => false,
            'div' => false,)
        );
        ?> <!--<label class="error-message">(*)</label>-->
        <span class="sp-total-day">
            <?php
            echo $this->Form->input('total_days', array(
                'type' => 'hidden',)
            );
            ?>
            <?php echo __('Total day'); ?> : <span id="total_days"><?php echo $this->request->data['Accountresume']['total_days']; ?></span>
        </span>
    </div>
    <div class="wrapper-sum-insured-page4 clearfix">
        <span class="size-span"><?php echo __('Sum Insured'); ?> :</span>
        <input type="text" id="SumInsured" value="<?php echo number_format($this->request->data['Accountresume']['sum_insured'], 2); ?>" class="inp-sum-insured" style="width:350px" name="sum_insured" /> <!--<label class="error-message">(*)</label>-->
        <?php
        echo $this->Form->input('Currency.Currency', array(
            'multiple' => false,
            'selected' => $currency['Currency']['id'],
            'empty' => false,
            'label' => false,
            'div' => false,)
        );
        echo $this->Form->input('currency', array(
            'type' => 'hidden',
            'value' => $this->request->data['Accountresume']['currency'],)
        );
        echo $this->Form->input('sum_insured', array(
            'type' => 'hidden',)
        );
        ?>
    </div>
    <div class="wrapper-rate-page4 clearfix">
        <span class="size-span"><?php echo __('Rate'); ?> :</span>
        <?php
        echo $this->Form->text('rate', array(
            'class' => 'inp-rate',
            'label' => false,
            'div' => false,)
        );
        ?> % <!--<label class="error-message">(*)</label>-->
    </div>
    <div class="wrapper-gross-pre-page4 clearfix">
        <span class="size-span">
            <?php
            echo $this->Form->input('gross_premium', array(
                'type' => 'hidden',)
            );
            ?>
            <?php echo __('Gross Premium'); ?> :
        </span>
        <span id="Gross_Premium"><?php echo number_format($this->data['Accountresume']['gross_premium'], 2); ?></span> <span class="selected_currency"><?php echo $this->data['Accountresume']['currency']; ?></span> 
    </div>
    <div class="wrapper-rate-page4 clearfix">
        <span class="size-span"><?php echo __('Order Hereon'); ?> :</span>
        <?php
        echo $this->Form->text('order_hereon', array(
            'class' => 'inp-rate',
            'label' => false,
            'div' => false,)
        );
        ?> % <!--<label class="error-message">(*)</label>-->
    </div>
    <div class="wrapper-gross-pre-page4 clearfix">
        <span class="size-span">
            <?php
            echo $this->Form->input('nett_premium', array(
                'type' => 'hidden',)
            );
            ?>
            <?php echo __('Nett Premium'); ?> :
        </span>
        <span id="Nett_Premium"><?php echo number_format($this->data['Accountresume']['nett_premium'], 2); ?></span> <span class="selected_currency"><?php echo $this->data['Accountresume']['currency']; ?></span> 
    </div>
    <div class="wrapper-rate-page4 clearfix">
        <span class="size-span"><?php echo __('Client Discount'); ?> :</span>
        <?php
        echo $this->Form->text('client_discount', array(
            'class' => 'inp-rate',
            'label' => false,
            'div' => false,)
        );
        ?> % <!--<label class="error-message">(*)</label>-->
    </div>
    <div class="wrapper-gross-pre-page4 clearfix">
        <span class="size-span">
            <?php
            echo $this->Form->input('order_premium', array(
                'type' => 'hidden',)
            );
            ?>
            <?php echo __('Order Premium'); ?> :
        </span>
        <span id="Order_Premium"><?php echo number_format($this->data['Accountresume']['order_premium'], 2); ?></span> <span class="selected_currency"><?php echo $this->data['Accountresume']['currency']; ?></span> 
    </div>
    <div class="wrapper-placement-detail clearfix">
        <span class="title-placement-detail"><?php echo __('PLACEMENT DETAILS'); ?></span>
        <?php
        foreach ($placementdetails as $placementdetail) {
            echo $this->Layout->placementDetailField($cur_data_market_full_repair[$placementdetail['Placementdetailt']['contact_id']]['Market'], $placementdetail['Placementdetailt'], true);
        }
        ?>
        <span id="placementdetailField"></span>
    </div>
    <div class="wrapper-payment-schedule clearfix">
        <span class="title-payment-schedule"><?php echo __('PAYMENT SCHEDULE'); ?></span>
        <div class="wrapper-content-payment-schedule clearfix">
            <table cellspacing="0" cellpadding="0" border="0" class="tbl-payment" style="margin-bottom:0">
                <tr class="tbl-payment-title">
                    <td class="td-from-producing-broker" style="text-align:left">
                        <?php echo __('FROM'); ?>
                        <select id="PaymentFromId" name="PaymentFrom" class="size-sel1-page4" style="width:120px">
                            <?php
                            foreach ($cur_data_producing_brokers as $key => $value) {
                                echo '<option value="' . $key . '">' . $value . '</option>';
                            }
                            ?>
                        </select>
                        <a class="button-in-form addPaymentscheduleField" href="JavaScript:void(0);" style="margin-left: 35px"><?php echo __('Add'); ?></a>
                    </td>
                    <td class="td-aih-commission"><!--<?php echo __('AIH COMMISSION'); ?>--></td>
                </tr>
            </table>
            <?php
            foreach ($paymentschedules as $paymentschedule) {
                echo $this->Layout->paymentscheduleField($paymentschedule['Paymentschedule'], $paymentschedule['Paymentschedule']['payer'], $paymentschedule['Paymentschedule']['payer_name'], $cur_data_market_full, true);
            }
            ?>
            <span id="paymentscheduleField"></span>
        </div>
    </div>
</div>
<div class="wrapper-button-form">
    <div class="button-form">
        <div class="button-aihre button-blue"><a href="JavaScript:void(0)" class="save">SAVE</a></div>
        <div class="button-aihre button-blue">
            <?php echo $this->Html->link(__('CANCEL'), array('plugin' => null, 'controller' => 'accountresumes', 'action' => 'index')); ?>
        </div>
        <div class="button-aihre button-blue">
            <?php
            echo $this->Html->link(__('DELETE'), array(
                'controller' => 'accountresumes',
                'action' => 'delete',
                $this->data['Accountresume']['id'],
                'token' => $this->params['_Token']['key'],), null, __('Are you sure want to delete this Resume?'));
            ?>
        </div>
        <div class="button-aihre button-blue"><a href="JavaScript:void(0)" class="cover_note"><?php echo __('COVER NOTE') ?></a></div>
        <div class="button-aihre button-blue"><a href="JavaScript:void(0)" class="debit_note"><?php echo __('DEBIT NOTE') ?></a></div>
        <div class="button-aihre button-blue"><a href="JavaScript:void(0)" class="premium_closing"><?php echo __('PREMIUM CLOSING') ?></a></div>
    </div>
</div>
<div class="wrapper-button-form">
    <div class="button-form">
        <div class="button-aihre button-blue">
            <a href="JavaScript:void(0)" class="download_pdf">
        <?php echo __('REVIEW & DOWNLOAD PDF') ?></a></div>
    </div>
</div>
<?php
echo $this->Form->end();
$validForm = "
    $(function(){
        $('a.save').click(function(){
            var error = true;
            var pattern, pattern2;
            // Date
            if($('#AccountresumeDate').val()==''){
                $('#AccountresumeDate').parent().children('label.error-message').remove();
                $('#AccountresumeDate').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else {
                $('#AccountresumeDate').parent().children('label.error-message').remove();
            }
            // Reference # 
            if($('#AccountresumeRefidEdit').val()==''){
                $('#AccountresumeRefidEdit').parent().children('label.error-message').remove();
                $('#AccountresumeRefidEdit').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else {
                $('#AccountresumeRefidEdit').parent().children('label.error-message').remove();
            }
            // Reinsured
            if($('#AccountresumeReinsured').val()==''){
                $('#AccountresumeReinsured').parent().children('label.error-message').remove();
                $('#AccountresumeReinsured').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else {
                $('#AccountresumeReinsured').parent().children('label.error-message').remove();
            }
            // Original Insured
            if($('#AccountresumeOriginalInsured').val()==''){
                $('#AccountresumeOriginalInsured').parent().children('label.error-message').remove();
                $('#AccountresumeOriginalInsured').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else {
                $('#AccountresumeOriginalInsured').parent().children('label.error-message').remove();
            }
            // From Date
            if($('#AccountresumeFromDate').val()==''){
                $('#AccountresumeFromDate').parent().children('label.error-message-first').remove();
                $('#AccountresumeFromDate').after('<label class=\"error-message-first\">This field is required</label>');
                error = false;
            } else {
                $('#AccountresumeFromDate').parent().children('label.error-message-first').remove();
                if($('#AccountresumeTotalDays').val()*1 < 1) {
                    $('#total_days').parent().children('label.error-message').remove();
                    $('#total_days').after('<label class=\"error-message\">Total days must greater than 0</label>');
                    error = false;
                } else {
                    $('#total_days').parent().children('label.error-message').remove();
                }
            }
            // To Date
            if($('#AccountresumeToDate').val()==''){
                $('#AccountresumeToDate').parent().children('label.error-message-second').remove();
                $('#AccountresumeToDate').after('<label class=\"error-message-second\">This field is required</label>');
                error = false;
            } else {
                $('#AccountresumeToDate').parent().children('label.error-message-second').remove();
                if($('#AccountresumeTotalDays').val()*1 < 1) {
                    $('#total_days').parent().children('label.error-message').remove();
                    $('#total_days').after('<label class=\"error-message\">Total days must greater than 0</label>');
                    error = false;
                } else {
                    $('#total_days').parent().children('label.error-message').remove();
                }
            }
            
            // Sum Insured
            if($('#SumInsured').val()==''){
                $('#SumInsured').parent().children('label.error-message').remove();
                $('#SumInsured').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else if($('#SumInsured').val()*1 < 0) {
                $('#SumInsured').parent().children('label.error-message').remove();
                $('#SumInsured').after('<label class=\"error-message\">This value can\'t be less than 0</label>');
                error = false;
            } else {
                pattern = /^\\$?[1-9][0-9]{0,2}(,[0-9]{3})*(\.[0-9]{1,2})?$/.test($('#SumInsured').val());
                if(pattern){
                    $('#SumInsured').parent().children('label.error-message').remove();
                } else {
                    $('#SumInsured').parent().children('label.error-message').remove();
                    $('#SumInsured').after('<label class=\"error-message\">This field is invalid.</label>');
                    error = false;
                }
            }
            // Rate
            if($('#AccountresumeRate').val()==''){
                $('#AccountresumeRate').parent().children('label.error-message').remove();
                $('#AccountresumeRate').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else if($('#AccountresumeRate').val()*1 <= 0) {
                $('#AccountresumeRate').parent().children('label.error-message').remove();
                $('#AccountresumeRate').after('<label class=\"error-message\">This value can\'t be less than 0</label>');
                error = false;
            } else if($('#AccountresumeRate').val()*1 > 100) {
                $('#AccountresumeRate').parent().children('label.error-message').remove();
                $('#AccountresumeRate').after('<label class=\"error-message\">This value can\'t be greater than 100</label>');
                error = false;
            } else {
                pattern = /^[1-9]{1}[0-9]*(\.[0-9]+)?$/.test($('#AccountresumeRate').val());
                pattern2 = /^[0]{1}(\.[0-9]+)?$/.test($('#AccountresumeRate').val());
                if(pattern || pattern2){
                    $('#AccountresumeRate').parent().children('label.error-message').remove();
                } else {
                    $('#AccountresumeRate').parent().children('label.error-message').remove();
                    $('#AccountresumeRate').after('<label class=\"error-message\">This field is invalid</label>');
                    error = false;
                }
            }
            // Order Hereon
            if($('#AccountresumeOrderHereon').val()==''){
                $('#AccountresumeOrderHereon').parent().children('label.error-message').remove();
                $('#AccountresumeOrderHereon').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else if($('#AccountresumeOrderHereon').val()*1 <= 0) {
                $('#AccountresumeOrderHereon').parent().children('label.error-message').remove();
                $('#AccountresumeOrderHereon').after('<label class=\"error-message\">This value can\'t be less than 0</label>');
                error = false;
            } else if($('#AccountresumeOrderHereon').val()*1 > 100) {
                $('#AccountresumeOrderHereon').parent().children('label.error-message').remove();
                $('#AccountresumeOrderHereon').after('<label class=\"error-message\">This value can\'t be greater than 100</label>');
                error = false;
            } else {
                pattern = /^[1-9]{1}[0-9]*(\.[0-9]+)?$/.test($('#AccountresumeOrderHereon').val());
                pattern2 = /^[0]{1}(\.[0-9]+)?$/.test($('#AccountresumeOrderHereon').val());
                if(pattern || pattern2){
                    $('#AccountresumeOrderHereon').parent().children('label.error-message').remove();
                } else {
                    $('#AccountresumeOrderHereon').parent().children('label.error-message').remove();
                    $('#AccountresumeOrderHereon').after('<label class=\"error-message\">This field is invalid</label>');
                    error = false;
                }
            }
            var order_hereon = $('#AccountresumeOrderHereon').val()*1;

            // Client Discount
            if($('#AccountresumeClientDiscount').val()==''){
                $('#AccountresumeClientDiscount').parent().children('label.error-message').remove();
                $('#AccountresumeClientDiscount').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else if($('#AccountresumeClientDiscount').val()*1 < 0) {
                $('#AccountresumeClientDiscount').parent().children('label.error-message').remove();
                $('#AccountresumeClientDiscount').after('<label class=\"error-message\">This value can\'t be less than 0</label>');
                error = false;
            } else if($('#AccountresumeClientDiscount').val()*1 == 0) {
                $('#AccountresumeClientDiscount').parent().children('label.error-message').remove();
                $('#AccountresumeClientDiscount').val(0);
            } else {
                pattern = /^[1-9]{1}[0-9]{0,1}(\.[0-9]+)?$/.test($('#AccountresumeClientDiscount').val());
                pattern2 = /^[0]{1}(\.[0-9]+)?$/.test($('#AccountresumeClientDiscount').val());
                if(pattern || pattern2){
                    $('#AccountresumeClientDiscount').parent().children('label.error-message').remove();
                } else {
                    $('#AccountresumeClientDiscount').parent().children('label.error-message').remove();
                    $('#AccountresumeClientDiscount').after('<label class=\"error-message\">This field is invalid</label>');
                    error = false;
                }
            }
            
            // Placement detail
            $('input[title=\"required_placementdetail\"]').each(function(){
                if($(this).val()==''){
                    $(this).parent().children('label.error-message').remove();
                    $(this).after('<label class=\"error-message\">This field is required</label>');
                    error = false;
                } else if($(this).val()*1 < 0) {
                    $(this).parent().children('label.error-message').remove();
                    $(this).after('<label class=\"error-message\">This value can\'t be less than 0</label>');
                    error = false;
                } else if($(this).val()*1==0) {
                    $(this).parent().children('label.error-message').remove();
                } else {
                    pattern = /^[1-9][0-9]{0,1}(\.[0-9]+)?$/.test($(this).val());
                    pattern2 = /^[0]{1}\.[1-9]{1}([0-9]*)?$/.test($(this).val());
                    if(pattern || pattern2){
                        $(this).parent().children('label.error-message').remove();
                    } else {
                        $(this).parent().children('label.error-message').remove();
                        $(this).after('<label class=\"error-message\">This field is invalid</label>');
                        error = false;
                    }
                }
            });
            $('input[title=\"required_placementdetail2\"]').each(function(){
                if($(this).val()==''){
                    $(this).parent().children('label.error-message').remove();
                    $(this).after('<label class=\"error-message\">This field is required</label>');
                    error = false;
                } else if($(this).val()*1 <= 0) {
                    $(this).parent().children('label.error-message').remove();
                    $(this).after('<label class=\"error-message\">This value must be greater than 0</label>');
                    error = false;
                } else {
                    pattern = /^[1-9][0-9]{0,1}(\.[0-9]+)?$/.test($(this).val());
                    pattern2 = /^[0]{1}\.[1-9]{1}([0-9]*)?$/.test($(this).val());
                    if(pattern || pattern2){
                        $(this).parent().children('label.error-message').remove();
                    } else {
                        $(this).parent().children('label.error-message').remove();
                        $(this).after('<label class=\"error-message\">This field is invalid</label>');
                        error = false;
                    }
                }
            });
            
            var contact_rate = 0;
            $('input[title=\"required_contact_rate\"]').each(function(){
                if($(this).val()==''){
                    $(this).parent().children('label.error-message').remove();
                    $(this).after('<label class=\"error-message\">This field is required</label>');
                    error = false;
                } else if($(this).val()*1 == 100) {
                    $(this).parent().children('label.error-message').remove();
                    contact_rate += $(this).val()*1;
                } else if($(this).val()*1 < 0) {
                    $(this).parent().children('label.error-message').remove();
                    $(this).after('<label class=\"error-message\">This value can\'t be less than 0</label>');
                    error = false;
                } else {
                    pattern = /^[1-9][0-9]{0,1}(\.[0-9]+)?$/.test($(this).val());
                    pattern2 = /^[0]{1}\.[1-9]{1}([0-9]*)?$/.test($(this).val());
                    if(pattern || pattern2){
                        $(this).parent().children('label.error-message').remove();
                        contact_rate += $(this).val()*1;
                    } else {
                        $(this).parent().children('label.error-message').remove();
                        $(this).after('<label class=\"error-message\">This field is invalid</label>');
                        error = false;
                    }
                }
            });
            
            if(100!=contact_rate) {
                $('#placementdetailField').parent().children('div.error-message').remove();
                $('#placementdetailField').before('<div class=\"error-message\">Total of Underwriter percentage must equal to 100</div>');
                error = false;
            } else {
                $('#placementdetailField').parent().children('div.error-message').remove();
            }
            
            // Brokerage
            $('input[title=\"required_date\"]').each(function(){
                if($(this).val()==''){
                    $(this).parent().children('label.error-message').remove();
                    $(this).after('<label style=\"display:block\" class=\"error-message\">This field is required</label>');
                    error = false;
                } else {
                    $(this).parent().children('label.error-message').remove();
                }
            });
            
            var id;
            var payment_amount = 0;
            $('input[title=\"required_amount\"]').each(function(){
                if($(this).val()==''){
                    $(this).parent().children('label.error-message').remove();
                    $(this).after('<label style=\"display:block\" class=\"error-message\">This field is required</label>');
                    error = false;
                } else if($(this).val()*1 < 0) {
                    $(this).parent().children('label.error-message').remove();
                    $(this).after('<label class=\"error-message\">This value can\'t be less than 0</label>');
                    error = false;
                } else {
                    id = $(this).attr('id').replace('broker_amount', '');
                    $(this).parent().children('label.error-message').remove();
                    payment_amount += $('#Paymentschedule'+id+'BrokerAmount').val()*1;
                }
            });
            
            var order_premium = $('#AccountresumeOrderPremium').val()*1;
            if(payment_amount!=order_premium) {
                $('#paymentscheduleField').parent().children('div.error-message').remove();
                $('#paymentscheduleField').before('<div class=\"error-message\">Payment must equal Order Premium</div>');
                error = false;
            } else {
                $('#paymentscheduleField').parent().children('div.error-message').remove();
            }
            
            if (error) {
                $('#AccountresumeAdminEditForm').submit();
            } else {
                if($('label[class*=\"error-message\"]').length > 0) {
                    $.scrollTo( 'label[class*=\"error-message\"]:eq(0)', 800 );
                } else {
                    $.scrollTo( 'div[class*=\"error-message\"]:eq(0)', 800 );
                }
            }
        });
        // Date
        $('#AccountresumeDate').change(function() {
            if($(this).val()==''){
                $(this).parent().children('label.error-message').remove();
                $(this).after('<label class=\"error-message\">This field is required</label>');
            } else {
                $(this).parent().children('label.error-message').remove();
            }
        }); 
        // Reference # 
        $('#AccountresumeRefidEdit').blur(function() {
            if($('#AccountresumeRefidEdit').val()==''){
                $('#AccountresumeRefidEdit').parent().children('label.error-message').remove();
                $('#AccountresumeRefidEdit').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else {
                $('#AccountresumeRefidEdit').parent().children('label.error-message').remove();
            }
        }); 
        // Reinsured
        $('#AccountresumeReinsured').blur(function() {
            if($('#AccountresumeReinsured').val()==''){
                $('#AccountresumeReinsured').parent().children('label.error-message').remove();
                $('#AccountresumeReinsured').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else {
                $('#AccountresumeReinsured').parent().children('label.error-message').remove();
            }
        }); 
        // Original Insured
        $('#AccountresumeOriginalInsured').blur(function() {
            if($('#AccountresumeOriginalInsured').val()==''){
                $('#AccountresumeOriginalInsured').parent().children('label.error-message').remove();
                $('#AccountresumeOriginalInsured').after('<label class=\"error-message\">This field is required</label>');
                error = false;
            } else {
                $('#AccountresumeOriginalInsured').parent().children('label.error-message').remove();
            }
        }); 
        // Brokerage
    });
    function recalculator() {
        var sb;
        var sum_insured = $('#AccountresumeSumInsured').val()*1;
        var rate = $('#AccountresumeRate').val()*1;
        // calc gross premium
        var gross_premium = sum_insured * rate /100;
        var total_days = $('#AccountresumeTotalDays').val()*1;
        if(total_days<365) {
            gross_premium = sum_insured * rate /100 * total_days /365;
        } 
        if(gross_premium > 0) {
            gross_premium = Accountresumes.roundNumber(gross_premium, 2);
            $('#AccountresumeGrossPremium').val(gross_premium);
            $('#AccountresumeGrossPremium').formatCurrency('#Gross_Premium');
            sb = $('select#CurrencyCurrency option:selected');
            $('#AccountresumeGrossPremium').parent().parent().children('span.selected_currency').html(sb.text());
        }

        var order_hereon = $('#AccountresumeOrderHereon').val()*1; 
        // calc nett premium
        var nett_premium = gross_premium * order_hereon /100;
        if(nett_premium > 0) {
            nett_premium = Accountresumes.roundNumber(nett_premium, 2);
            $('#AccountresumeNettPremium').val(nett_premium);
            $('#AccountresumeNettPremium').formatCurrency('#Nett_Premium');
            sb = $('select#CurrencyCurrency option:selected');
            $('#AccountresumeNettPremium').parent().parent().children('span.selected_currency').html(sb.text());
        }

        var client_discount = $('#AccountresumeClientDiscount').val()*1; 
        // calc nett premium
        var order_premium = nett_premium * (100 - client_discount) /100;
        if(order_premium > 0) {
            order_premium = Accountresumes.roundNumber(order_premium, 2);
            $('#AccountresumeOrderPremium').val(order_premium);
            $('#AccountresumeOrderPremium').formatCurrency('#Order_Premium');
            sb = $('select#CurrencyCurrency option:selected');
            $('#AccountresumeOrderPremium').parent().parent().children('span.selected_currency').html(sb.text());
        }

        // calc from order_premium
        $('input[title=\"required_amount\"]').each(function(){
            var id = $(this).attr('id').replace('broker_amount', '');
            $('#broker_amount'+id).formatCurrency();
            var broker_amount = $('#broker_amount'+id).val().replace(/,/gi, '')*1; 
            if(broker_amount > 0) {
                broker_amount = Accountresumes.roundNumber(broker_amount, 2);
                var contact_rate, aih_rate, market_amount; 
                var aih_amounts = 0;
                $('input[name=\"Markets[]\"]').each(function(){
                    var market_id = $(this).val();
                    contact_rate = $('#rel_market'+market_id+' input[name*=\"contact_rate\"]').val()*1; 
                    aih_rate = $('#rel_market'+market_id+' input[name*=\"aih_rate\"]').val()*1; 
                    market_amount = broker_amount * contact_rate /100 * (100 - aih_rate) /100;
                    market_amount = Accountresumes.roundNumber(market_amount, 2);
                    aih_amounts += market_amount;
                    $('#Paymentschedule'+id+'RelMarketAmount'+market_id).val(market_amount);
                    $('#Paymentschedule'+id+'RelMarketAmount'+market_id).formatCurrency('#market_amount'+id+market_id);
                });
                $('#Paymentschedule'+id+'AihAmount').val(Accountresumes.roundNumber(broker_amount - aih_amounts, 2));
                $('#Paymentschedule'+id+'AihAmount').formatCurrency('#aih_amount'+id);
            }
        });
    }";
$this->Html->scriptBlock($validForm, array('inline' => false));
?>